package com.itheima.d2_reflect;

import java.lang.reflect.Constructor;

public class Test2Constructor {
    public static void main(String[] args) throws Exception {
        Class c= Cat.class;
        //Constructor[] constructors=c.getConstructors();
        Constructor[] constructors=c.getDeclaredConstructors();
        for(Constructor constructor:constructors){
            System.out.println(constructor.getName()+"--->"+constructor.getParameterCount());
        }


        Constructor constructor2=c.getDeclaredConstructor(String.class,int.class);
        System.out.println(constructor2.getName()+"--->"+constructor2.getParameterCount());

        Constructor constructor3=c.getDeclaredConstructor();
        System.out.println(constructor3.getName()+"--->"+constructor3.getParameterCount());
        //暴力反射
        constructor3.setAccessible(true);
        Cat cat=(Cat) constructor3.newInstance();
        System.out.println(cat.toString());

        constructor2.setAccessible(true);
        Cat cat1=(Cat) constructor2.newInstance("叮当猫",12);
        System.out.println(cat1.toString());
    }
}
